package org.thread.Homework02;/*
 *@Author: gjh
 *Date: 2025/3/11 11:53
 *Describe:
 */

public class MyThread extends Thread{
    @Override
    public void run() {
        while (true){
            // 模拟的采集数据
            int num = 0;
            for (int i = 0; i < 100; i++) {
                num += i;
                System.out.println("接收数据："+num);
            }

            // 获取是否中断状态
            boolean flag = Thread.currentThread().isInterrupted();
            // 如flag=true 则为中断
            if(flag){
                System.out.println("终止线程");
                break;
            }

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                System.out.println("睡眠被中断的状态：" +
                    Thread.currentThread().isInterrupted());
            }
        }
    }
}
